function TowersPanel(x, y, w, h, c, r, tt, td)
{
  var _x;
  var _y;
  var _root;
  var _width;
  var _height;
  var _columns;
  var _rows;
  var _towerTypes;
  var _td;
  var textBox;
  
  this._x = x;
  this._y = y;
  this._width = w;
  this._height = h;
  this._columns = c;
  this._rows = r;
  this._towerTypes = tt;
  this._td = td;
}

TowersPanel.prototype.Init = function()
{
  this._root = new MovieClip();
  this._root.x = this._x;
  this._root.y = this._y;
  
  //dibujo el fondo
  this._root.DrawRectangle(0, 0, this._width, this._height, '#AAAAAA', 1);
  this._root.DrawRectangle(0, this._height, this._width, 80, '#CCCCCC', 1);
  this.textBox = new MovieClip("tPanel_textBox", this._root);
  this.textBox.y = this._height;
  
  //dibujo las líneas de la grilla
  var columnWidth = this._width / this._columns;
  var columnHeight = this._height / this._rows;
  for(var c = 0; c <= this._columns; c++)
  {
    this._root.DrawLine(c * columnWidth, 0, c * columnWidth, this._height, "#666666", 1);
  }
  for(var r = 0; r <= this._rows; r++)
  {
    this._root.DrawLine(0, r * columnHeight, this._width, r * columnHeight, "#666666", 1);
  }
  
  //posiciono las torres
  for(var i = 0; i < this._towerTypes.length; i++)
  {
    var row = Math.floor(i / this._columns);
    var column = i - (row * this._columns);
    
    var t = new MovieClip(i, this._root);
    t.LoadResource(this._towerTypes[i].resourceName);
    t.x = column * columnWidth + 20;
    t.y = row * columnHeight + 20;
	//agrego los eventos
	t._root.addEventListener("mouseup", Delegate.create(this, this.onTowerTypeClick, this._towerTypes[i]), false);
  }
}

TowersPanel.prototype.onTowerTypeClick = function(evt, ttype)
{
	this._td.DropNewTower(ttype);
	this.textBox.DrawString(5, 15, ttype.resourceName, "#660000");
}

TowersPanel.prototype.UpdateText = function()
{
	//this.textBox.
}

TowersPanel.prototype.toString = function()
{
  return "[TowersPanel]";
}